import { queryDashboardStatistics } from '../services/dashboard';

export default {
  namespace: 'dashboard',
  state: {
    statistics: {}
  },

  effects: {
    *fetchDashboardStatistics({payload, callback}, {call, put}) {
      const response = yield call(queryDashboardStatistics, payload);
      if(callback) callback(response);
      yield put({
        type: 'updateStatistics',
        payload: {...response},
      });
    },
  },

  reducers: {
    updateStatistics(state, action) {
      return {
        ...state,
        statistics: action.payload.totals,
      }
    }
  },
};
